<#include "/include/lib.html"/>
<style>
	.mg-title{
		height:30px;line-height:30px;font-size:15px;text-align:center;background:#39AFE0;color:#fff;font-weight:bold;border-radius:5px 5px 0px 0px;
	}
	.mg-form{
		border:1px solid #39afe0;height:200px;
		padding:10px;
	}
	.mg-form table tr{
		
	}

	.mg-form table tr th{
		text-align: right;
		font-size: 12px;
	}
</style>
<div style="width:1000px;margin:0 auto;">
	<fieldset>
	 	<legend>数据库表数据迁移-v2.0 2015-10-29 16:30</legend>
	 	<div>
	 		版本2.0特性：<br/>
	 		1.支持跨数据库，oracle,sql server,mysql.(后续可以添加支持)<br/>
	 		2.接收用户界面输入值，来配置相关参数。<br/>
	 		注意事项：<br/>
	 		1.请务必输入所有参数，尽可能保持正确（只是做了最基本的不空验证）。<br/>
	 		2.数据库的URL连接，不要有\（反斜杠）。<br/>
	 	</div>
	 </fieldset>
	<div>
	<fieldset>
	 	<legend>URL示例:</legend>
		1.Mysql : jdbc:mysql://127.0.0.1:3306/dbname<br/>
		2.SqlServer : jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test<br/>
		3.Oracle:jdbc : oracle:thin:@127.0.0.1:1521:ORCL<br/>
	</fieldset>
	 <div style="width:450px;float:left;margin-top:20px;">
	 	<div class="mg-title">数据源[from]</div>
	 	<form class="mg-form">
		 	<table>
		 		<tr>
		 			<th>数据库类型：</th>
		 			<td>
		 				<select id="from_db_type">
		 					<option value="mysql">mysql</option>
		 					<option value="sqlserver">sqlserver</option>
		 					<option value="oracle">oracle</option>
		 				</select>
		 			</td>
		 		</tr>
		 		<tr>
		 			<th>URL：</th>
		 			<td>
		 				<input type="text" id="from_url" style="width:350px;">
		 			</td>
		 		</tr>
		 		<tr>
		 			<th>用户名：</th>
		 			<td>
		 				<input type="text" id="from_username">
		 			</td>
		 		</tr>
		 		<tr>
		 			<th>密码：</th>
		 			<td>
		 				<input type="password" id="from_password">
		 			</td>
		 		</tr>
		 	</table>
		 </form>
	 </div>
	 <div style="width:90px;float:left;height:200px;margin-top:20px;">
	 	<span style="padding-left:5px;margin-top:60px;display:block;text-align:center;color:red;">
	 		表名：
	 	</span>
	 	<span style="padding-left:5px;">
	 		<input type="text" style="width:90px;" id="table_name">
	 	</span>
	 	<img src="${root!}/static/image/jiantou.jpg" alt="" width="90px" height="50px" style="margin-left:5px;">
	 </div>
	 <div style="width:450px;float:right;margin-top:20px;">
	 	<div class="mg-title">目标源[to]</div>
	 	<form class="mg-form">
		 	<table>
		 		<tr>
		 			<th>数据库类型：</th>
		 			<td>
		 				<select id="to_db_type">
		 					<option value="mysql">mysql</option>
		 					<option value="sqlserver">sqlserver</option>
		 					<option value="oracle">oracle</option>
		 				</select>
		 			</td>
		 		</tr>
		 		<tr>
		 			<th>URL：</th>
		 			<td>
		 				<input type="text" id="to_url" style="width:350px;">
		 			</td>
		 		</tr>
		 		<tr>
		 			<th>用户名：</th>
		 			<td>
		 				<input type="text" id="to_username">
		 			</td>
		 		</tr>
		 		<tr>
		 			<th>密码：</th>
		 			<td>
		 				<input type="password" id="to_password">
		 			</td>
		 		</tr>
		 	</table>
		 </form>
	 </div>
	 <div style="text-align:center;">
	 	<button class="btn btn-primary btn-lg" id="start-btn"> 开始数据迁移 </button>
	 </div>
</div>
 <script>
 	(function(){
 		$("#start-btn").click(function(){
 			//验证
 			var res = check();
 			if(res.check){
 				$.ajax({
	 				url:mg.rootpath() + "/importByInterface",
	 				async:false,
	 				type:"post",
	 				data:res.data,
	 				crossDomain:true,
	 				jsonType:"json",
	 				success:function(data){
	 					layer.alert(data.msg);
	 				},
	 				error:function(data){
	 					layer.alert("出错啦！");
	 				}
	 			});
 			}
 			
 		});
 	})();

 	//验证
 	function check(){
 		var res = {};
 		var from_db_type = $("#from_db_type").val();
 		var from_url = $("#from_url").val();
 		var from_username = $("#from_username").val();
 		var from_password = $("#from_password").val();

 		var table_name = $("#table_name").val();

 		var to_db_type = $("#to_db_type").val();
 		var to_url = $("#to_url").val();
 		var to_username = $("#to_username").val();
 		var to_password = $("#to_password").val();

 		if(isNotEmpty(from_db_type) && 
 			isNotEmpty(from_url) && 
 			isNotEmpty(from_username) && 
 			isNotEmpty(from_password) && 
 			isNotEmpty(table_name) && 
 			isNotEmpty(to_db_type) && 
 			isNotEmpty(to_url) && 
 			isNotEmpty(to_username) && 
 			isNotEmpty(to_password)){
 			res.check = true;
 			res.data = {
 				"from_db_type" : from_db_type,
 				"from_url" : from_url,
 				"from_username" : from_username,
 				"from_password" : from_password,
 				"table_name" : table_name,
 				"to_db_type" : to_db_type,
 				"to_url" : to_url,
 				"to_username" : to_username,
 				"to_password" : to_password
 			};
 		}else{
			layer.alert("请确保填写信息完整并正确！\r\n谢谢合作！");
 			res.check = false;
 		}
 		return res;
 	}
 	//验证非空
 	function isNotEmpty(str){
 		if(str!=null && str!=undefined && str.length>0){
 			return true;
 		}else{
 			return false;
 		}
 	}
 </script>
